<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />

        <!-- 表格顶部菜单 -->
        <TableHeader
            :buttons="['refresh', 'add', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
            :quick-search-placeholder="t('quick Search Placeholder', { fields: t('corplib.quick Search Fields') })"
        />

        <!-- 表格 -->
        <!-- 要使用`el-table`组件原有的属性，直接加在Table标签上即可 -->
        <Table ref="tableRef" />

        <!-- 表单 -->
        <PopupTabs />
    </div>
</template>

<script setup lang="ts">
import { ref, provide, onMounted, reactive } from 'vue'
import baTableClass from '/@/utils/baTable'
import { corplib,dEPARTMENT } from '/@/api/controllerUrls'
import { defaultOptButtons } from '/@/components/table'
import { baTableApi } from '/@/api/common'
import { useI18n } from 'vue-i18n'
import PopupTabs from './popupTabs.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'


const { t } = useI18n()
const state:{
    departList:any[]
} = reactive({
    departList:[]
})

const route = useRoute()
const type = route.name === 'corplib/customer'? 1:2
console.log(route)

const tableRef = ref()
const optButtons = defaultOptButtons(["edit","delete"])
const baTable = new baTableClass(
    new baTableApi(corplib),
    // new baTableApi('/admin/corplib.customer/'),
    {
        pk: 'CORP',
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: t('corplib.CORP'), prop: 'CORP', align: 'center' },
            { label: t('corplib.CORPNAME'), prop: 'CORPNAME', align: 'center' },
            { label: t('corplib.ACTIVE'), prop: 'ACTIVE', align: 'center' ,render:'tag',replaceValue:{'0':'无效','1':'有效'}},

            { label: t('corplib.PFLAG'), prop: 'PFLAG', align: 'center',render:'tag',replaceValue:{'0':'否','1':'是',null:'否'} },
            { label: t('corplib.DEPT'), prop: 'DEPTNAME', align: 'center',operator:false },
            { label: t('corplib.DEPT'), prop: 'DEPT', align: 'center',show:false,comSearchRender: 'remoteSelect', remote: {
                pk:'DEPTID',
                field: 'DEPTNAME',
                remoteUrl:dEPARTMENT +'index',
                params: {},
            } },

            { label: t('operate'), align: 'center', width: 100, render: 'buttons', buttons: optButtons, operator: false },
        ],
        dblClickNotEditColumn: [undefined, ],
        defaultOrder: { prop: 'OPTIME', order: 'desc' },
    },
    {
        defaultItems: [],
    }
)

provide('baTable', baTable)

onMounted(() => {
    baTable.table.ref = tableRef.value
    // type 1 为客户 2 为供应商

    if(route.query.code){
        baTable.table.filter.code = route.query.code
    }
    baTable.table.filter!.type = type
    // baTable.table.filter.items.type = type
    baTable.mount()
    baTable.getIndex()?.then(() => {
        baTable.initSort()
        baTable.dragSort()
    })
})


</script>

<script lang="ts">
import { defineComponent } from 'vue'
import { useRoute } from 'vue-router'
import createAxios from '/@/utils/axios'
export default defineComponent({
    name: 'corplib',
})
</script>

<style scoped lang="scss"></style>
